Readme for model folder

This folder contains codes and computed model and counterfactual estimates, as well as codes and instructions to replicate 
the bootstrap procedure used for inference.

A list of codes is provided at the end of this document. First I provide instructions on how to replicate the main results in 
the paper. All results were computed using Matlab 2018b in a Windows 2010 system, Intel Xeon CPU E5-2650 v4 @ 2.20GHz, 64 GB (RAM).

	1. Run estimation_full.m. This code runs the main estimation procedure for the baseline specification. For the alternative
	   specification using sugarcane ethanol as benchmark price run estimation_ethanol.m. This will save Results/full.mat 
	   with baseline point estimates. The output will be sufficient to replicate point estimates in 
	   Article Table 2: "Payoff and fixed cost estimates."  
	   
	   1.1 It will also generate the plots in Article Figure 4: "p_t (sugar price) and r_it (other uses return) series" 
	       when the code calls GenExoTimeState.m. This will save Resuls/OutReturn.eps and Resuls/SugarPrice.eps.
	   
	   1.2 With the opt variable generated by the code above loaded. Run DescriptivesPaper(opt) to 
			- generate general descriptive  statistics Article Table 1: "Field Characteristics";
			- generate replanting by cohort Article Figure 2: "Replanting age by cohort".
			- generate Article Figure 3: "Conditional probability of sugarcane expansion". It saves 
			  Figures/sugar_distance.eps and Figures/sugar_potyield.eps
	
	2. With results from previous step loaded (full.mat), run CFbase_p05.m for baseline counterfactual simulations. This will save
	   Results/full_CF.mat.
	
	3. With results from previous step loaded (full_CF.mat), run CFTables05.m. This will generate point estimates reported in
	   Article Table 3: "Long-run elasticities".
	
	4. Next run CFCarbon.m. It will generate Results/full_TableDec.csv which is Article Table 4: "Marginal Expansion and carbon emissions".
	   The code will also display carbon payback times discussed in the article.
	
	5. Next run CFPolicy.m for final sugarcane ethanol policy simulation in Article Table 5: "Effects of 5 billion gallons sugarcane ethanol 
	   mandate".
	   
	6. Bootstrap procedure:
		
		6.1 Run Bootstrap/full_b1_b80.m to run the bootstrap repetitions for the baseline specification and ethanol_b1_b80.m for alternative.
			I highly recomend this be paralelized in a computing cluster. This will generate the bootstrap results files that are compressed in
			full.tar and ethanol.tar.
		
		6.2 Run EstTables_boot.m to generate bootstrap std errs for baseline specification estimates. Change code accordingly to generate std errs
			for alternative 'ethanol' specification. Those are the std errs reported in Article Table 2: "Payoff and fixed cost estimates."
		
		6.2 Run CFBootRun_1to80.m to run counterfactual simulations for each bootstrap repetition. This will save Bootstrap/CF/CF_full_b'x'.m for 
			'x' running from 1 to 80 for the simulations for each bootstrap repetition. 
			
		6.3 Run CFTables05_boot.m to generate table with bootstrap std errs for Article Table 3: "Long-run elasticities".
		

%% List of files in Model folder:
	- AM_Estimation2.m: Estimate dynamic model using the NPL method proposed by Aguirregabiria and Mira (2003). Error correction for 
	                    underobserved replanting based on Arcidiacono and Miller (2011).
	- BoxesCreate.m:    Create boxes for sugarcane proximity regions.
	- BoxesProximityUpdate.m: Updates sugarcane proximity in foward simulations.
	- CFbase_p05.m:     Runs point estimates counterfactual simulation.
	- CFboot_p05.m:     Base for running bootstrap counterfactual simulations.
	- CFBootRun_1to80.m: Runs bootstrap counterfactual simulations.
	- CFCarbon.m:       Uses simulations to compute counterfactual carbon emissions
	- CFPolicy:         Counterfactual ethanol mandate exercise.
	- CFTables05_boot:  Compiles bootstrap counterfactual simulations and generates std errs for estimated elasticities.
	- CFTables05.m:     Compiles baseline simulation and generates elasticities reported in article.
	- ChoiceProb.m:     Computes logit choice probability in model estimation.
	- ClassStates.m:    Classifies continuous variables into discrete states.
	- clogit.m:         Conditional logit estimation.
	- DescriptivesPaper.m: Paper descriptive statistics. See 1.2 above.
	- Estimation_ethanol.m: MASTER code for estimating alternative spec model (see 1 above).
	- Estimation_full.m: MASTER code for estimating baseline spec model (see 1 above).
	- EstTables_boot.m: Generate bootstrap std errs for baseline specification estimates (see 6.1 above).
	- FieldAge.m:       Generates field age variable ('a_it' in the article) from CANASAT land use classification.
	- FirstStage.m:     First stage conditional logit to start NPL iteration.
	- GenExoFixedStates.m: Generates state variables for fixed (over time) state variables.
	- GenExoTimeStates.m: Generates state variables for time-varying state state variables. Includes AR estimation.
	- GenExoTimeStatesBoot.m: Same as above but used in bootstrap procedure.
	- GenStateVariables.m: Creates state variables. Calls GenExoTimeStates.m and GenExoFixedStates.m codes.
	- GenStateVariablesBoot.m: Same as above but used in bootstrap procedure.
	- kernel.n:         Kernel function used in nonparametric plots.
	- KernelRegression.m: Kernel regression of y on x variables.
	- LandUseClass.m:   Generates state variables for land use classes (MapBiomas)
	- LikAM.m:          Arcidiacono and Miller (2011) likelihood function.
	- LikNPL.m:         Aguirregabiria and Mira (2003) NPL likelihood function.
	- ols.m:            OLS regression.
	- OutsideOptionModelSimple.m: Outside option return process classification and discretization.
	- Payoff.m:         Payoff function used in estimation.
	- prepdataM10.m:    Master code for getting the data ready for estimation.
	- ProgressBar.m:    Simple progress bar.
	- SimulationExoTimeStatesNoShock.m: Runs forward simulation for exogenous time-varying state variables 
						(prices and returns)
	- SimulationForward.m: Simulates whole system one step forward in time.
	- SimulationPathsLong.m: Simulates whole system 150 steps forward in time. Calls SimulationForward.m.
	- StatesMapping.m:  Classification of state variables pre-estimation.
	- StateTrans.m:     Computes state transition matrix. Each (n,m) element is the prob of moving from state n to state m
	- subsample.m:      Draws a random subsample of the data.
	- UpdateUHProb2.m:  Update unobserved heterogeneity probability in estimation (EM estimation step).
	- ValueFunction.m   Computes value function for the model by iteration.
	- VarTauchen.m      Tauchen (1982) discretization approach for multivariate time series.

		